package com.hl.service;

import com.hl.mapper.ArticleMapper;
import com.hl.pojo.Article;
import com.hl.util.GeneralResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Map;

@Service
public class ArticleServiceImpl implements ArticleService{
    @Autowired
    private ArticleMapper articleMapper;
    @Override
    public List<Article> getAllArticleMessage() {
        return articleMapper.getAllArticleMessage();
    }

    @Override
    public GeneralResult souSuoArticleMessage(Map<String, Object> map) {
        List<Map<String,Object>> list = articleMapper.souSuoArticleMessage(map);
        return GeneralResult.message(200,"查询成功",list);
    }

    @Override
    public GeneralResult xinZengArticleMessage(Map<String, Object> map) {
        Integer category_id = articleMapper.searchByCategory_name((String) map.get("category_name"));
        map.put("category_name",category_id);
        Integer num = articleMapper.xinZengArticleMessage(map);
        return GeneralResult.message(200,"新增成功",num);
    }

    @Override
    public GeneralResult shanChuArticleMessage(Integer id) {
        Integer num = articleMapper.shanChuArticleMessage(id);
        return GeneralResult.message(200,"删除成功",num);
    }

    @Override
    public GeneralResult xiuGaiArticleMessage(Map<String, Object> map) {
        Integer category_id = articleMapper.searchByCategory_name((String) map.get("category_name"));
        map.put("category_name",category_id);
        Integer num = articleMapper.xinZengArticleMessage(map);
        return GeneralResult.message(200,"修改成功",num);
    }

    @Override
    public GeneralResult queDingShangChuan(String img_path) {
        Integer num = articleMapper.queDingShangChuan(img_path);
        return GeneralResult.message(200,"上传成功",num);
    }
}
